package st.business.tepth.business.user.busnumber.preholder.repair;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;
import st.business.tepth.R;
import st.business.tepth.R2;
import st.business.tepth.business.bean.PreWorkInfoBean;
import st.business.tepth.business.businfo.BusInfoDelegate;
import st.business.tepth.business.event.StartBrotherEvent;
import st.business.tepth.manager.UserManager;
import st.shadow.library.core.base.mvp.MvpFragment;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-04-11 15:38
 * 小修待处理
 */

public class PreRepairDelegate extends MvpFragment<PreRepairPresenter> implements PreRepairContract.View {
    public static PreRepairDelegate newInstance(int id) {
        Bundle bundle = new Bundle();
        bundle.putInt("id", id);
        PreRepairDelegate delegate = new PreRepairDelegate();
        delegate.setArguments(bundle);
        return delegate;
    }

    @BindView(R2.id.recycler_view)
    RecyclerView mRecyclerView;
    @BindView(R2.id.tv_work_type)
    TextView mTvType;
    private PreRepairAdapter mPreWorkAdapter;
    private int mRepairId;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mRepairId = bundle.getInt("id");
        }
    }

    @Override
    public PreRepairPresenter getPresenter() {
        return new PreRepairPresenter(this);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_pre_work;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity));

    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        mRecyclerView.setAdapter(mPreWorkAdapter = new PreRepairAdapter(R.layout.item_complete_check_un_edit,
                null));
        mPresenter.getInfo(UserManager.getInstance().getToken(),
                mRepairId);
    }

    @Override
    public void showData(PreWorkInfoBean infoBean) {
        mTvType.setText(infoBean.getTypeName());
        if (mPreWorkAdapter != null) {
            mPreWorkAdapter.setNewData(infoBean.getWorkList());
        }
    }

    @Override
    public void showError(String msg) {

    }

    @OnClick(R2.id.tv_bus_info)
    public void onShowBusInfo() {
        EventBus.getDefault().post(new StartBrotherEvent(BusInfoDelegate.newInstance(mRepairId)));
    }

}